package com.momo.hotel.controller;

import com.momo.hotel.dao.pojo.TbHotelBrank;
import com.momo.hotel.dao.pojo.ext.TbRoomList;
import com.momo.hotel.dto.GetHotels;
import com.momo.hotel.dto.SearchHotels;
import com.momo.hotel.service.HotelRoomService;
import com.momo.hotel.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class HotelController {

    @Autowired
    HotelService hotelService;

    @Resource
    HotelRoomService hotelRoomService;
    /**
     * 查询酒店
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectHotels")
    public Object selectHotels() {
        List<TbHotelBrank> tbHotelBrankList = hotelService.selectHotels();
        return tbHotelBrankList;
    }
    /*
     * 获取酒店品牌详情的id，并setAttribute
     *
     * @param request
     * @return
     */
    @RequestMapping("hotelDetail")
    public String hotelDetail(HttpServletRequest request) {
        String id = request.getParameter("id");
        List<TbRoomList> tbRoomList = hotelService.roomList(Integer.parseInt(id));
        request.getSession().setAttribute("tbRoomList", tbRoomList);
        return "rooms-list";
    }
    /**
     * 根据getAttribute获取新闻详情
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("hotelDetail1")
    public List<TbRoomList> hotelDetail1(HttpServletRequest request) {
        List<TbRoomList> tbRoomList = (List<TbRoomList>)request.getSession().getAttribute("tbRoomList");
        return tbRoomList;
    }


    @ResponseBody
    @RequestMapping(value = "getRooms",produces = "application/json;charset=utf-8")
    public Object getRooms(@RequestBody SearchHotels searchHotels,HttpServletRequest request){
        List<GetHotels> hotels = hotelRoomService.selectHotels(searchHotels);
        request.getSession().setAttribute("hotels",hotels);
        //Object hotels1 = request.getSession().getAttribute("hotels");
        //System.out.println("11111111111111  "+hotels1.toString());
        return hotels;
    }
    @ResponseBody
    @RequestMapping(value = "getRoomsBySession",produces = "application/json;charset=utf-8")
    public Object getRoomsBySession(HttpServletRequest request){

        List<GetHotels> hotels = (List<GetHotels>) request.getSession().getAttribute("hotels");
        return hotels;
    }
}
